package com.rxz.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.rxz.entity.Result;
import com.rxz.service.BmapService;
import com.rxz.utils.ResultUtil;
import jakarta.annotation.Resource;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.stereotype.Service;

@Service
public class BmapServiceImpl implements BmapService {

    @Autowired
    private StringRedisTemplate redisTemplate;

    public final static String CHECK_IN_KEY = "rxz_checkIn";

    @Override
    public Result checkIn(Integer id) {
        Boolean bit = redisTemplate.opsForValue().getBit(CHECK_IN_KEY, id);
        if (bit) {
            return ResultUtil.success("您已经签到成功！");
        }
        return ResultUtil.error(406,"您签到失败！");
    }

    @Override
    public Result login(Integer id) {
        Boolean setBit = redisTemplate.opsForValue().setBit(CHECK_IN_KEY, id, true);
        System.out.println(setBit);
        if (setBit) {
            return ResultUtil.success("操作成功！");
        }
        return ResultUtil.error(406,"操作失败！");
    }

    @Override
    public Result countTodayCheckIn() {
        return null;
    }
}
